home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / doslynx / src / turlvie6.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  6.0 KB  |  199 lines

  1. //    Copyright (c) 1993, University of Kansas, All Rights Reserved
  2. //
  3. //    Class:        TURLView
  4. //    Include File:    turlview.h
  5. //    Purpose:    Provide the view of a URL
  6. //    Remarks/Portability/Dependencies/Restrictions:
  7. //    Revision History:
  8. //        12-27-93    created
  9. //        02-02-94    Began a major revision to fully handle a
  10. //                multiple document interface with WWW, take
  11. //                over the formatting and drawing of the
  12. //                old gridtext functions of HText, and optimize
  13. //                memory usage, selecting anchors, the usage of
  14. //                HText's new image file.  See gridtext.
  15. //        02-09-94    Split all members into seperate files.
  16. #define Uses_TScreen
  17. #include"turlview.h"
  18.  
  19. void TURLView::draw()    {
  20. //    Purpose:    Draws the view on the screen.
  21. //    Arguments:    void
  22. //    Return Value:    void
  23. //    Remarks/Portability/Dependencies/Restrictions:
  24. //        This member takes the place of any possible output in
  25. //        the gridtext functions.
  26. //    Revision History:
  27. //        01-10-94    created
  28. //        02-01-04    Endlessly complicated this function by taking
  29. //                all formatting away from the gridtext
  30. //                functions also.
  31. //        02-22-94    Began modifications to work with the
  32. //                serialized rendered image produced by
  33. //                FormatIntoLines.
  34. //                Would create a buffer to read data into,
  35. //                but is redundant since file io is already
  36. //                buffered.  Maybe later as a speed increase.
  37.  
  38.     //    Drawing buffer.
  39.     TDrawBuffer TDB;
  40.  
  41.     //    Determine the video's mode and set our index into a manual
  42.     //    pallette for each display mode.
  43.     auto int usi_colorindex;
  44.     switch(TScreen::screenMode & 0x00FF)    {
  45.     case TDisplay::smMono:
  46.         usi_colorindex = 1U;
  47.         break;
  48.     case TDisplay::smBW80:
  49.         usi_colorindex = 2U;
  50.         break;
  51.     default:
  52.         usi_colorindex = 0U;
  53.         break;
  54.     }
  55.  
  56.     //    Figure the size of a buffer to read in all information needed
  57.     //    to draw the view.
  58.     auto Line L_draw;
  59.     auto signed long int sli_amount;
  60.     auto signed long int sli_offset;
  61.     //    First, read into mem the last line viewable.
  62.     sli_offset = (signed long int)(TNSCp_lines->at((delta.y + size.y - 1
  63.         < limit.y) ? delta.y + size.y - 1: limit.y - 1));
  64.     fsp_temp->seekg(sli_offset);
  65.     fsp_temp->read((char *)(&L_draw), sizeof(Line));
  66.     //    Figure the amount.
  67.     sli_amount = sli_offset + (signed long int)sizeof(Line) +
  68.         (signed long int)L_draw.ssi_length -
  69.         (signed long int)(TNSCp_lines->at(delta.y));
  70.     //    Reset the offset to the offset of the first viewable line.
  71.     sli_offset = (signed long int)(TNSCp_lines->at(delta.y));
  72.     fsp_temp->seekg(sli_offset);
  73.     //    Create a buffer and fill it.
  74.     auto char *cp_draw = new char[(size_t)sli_amount];
  75.     if(cp_draw == NULL)    {
  76.         doslynxmessage("Not enough memory to draw view.");
  77.         return;
  78.     }
  79.     fsp_temp->read(cp_draw, (signed short int)sli_amount);
  80.     if(fsp_temp->gcount() != sli_amount)    {
  81.         doslynxmessage("Error in reading rendered image file.");
  82.         delete[](cp_draw);
  83.         return;
  84.     }
  85.  
  86.     //    If the selected anchor is not within the part of the rendered
  87.     //    file read, then we should select the first viewable anchor.
  88.     if(TAp_selected != NULL)    {
  89.         if(TAp_selected->getEnd() <= sli_offset || TAp_selected->
  90.             getBegin() >= sli_offset + sli_amount)    {
  91.             //    Attempt to find an anchor in the view.
  92.             auto TextAttribute *TAp_saveSelected = TAp_selected;
  93.             auto ccIndex ccI;
  94.  
  95.             for(ccI = 0; ccI < TNSCp_anchors->getCount(); ccI++)
  96.             {
  97.                 TAp_selected = (TextAttribute *)(TNSCp_anchors
  98.                     ->at(ccI));
  99.                 if(TAp_selected->getEnd() >= sli_offset &&
  100.                     TAp_selected->getBegin() <= sli_offset
  101.                     + sli_amount)    {
  102.                     break;
  103.                 }
  104.             }
  105.  
  106.             //    Restore the old anchor if none found.
  107.             if(ccI == TNSCp_anchors->getCount())    {
  108.                 TAp_selected = TAp_saveSelected;
  109.             }
  110.         }
  111.     }
  112.  
  113.     //    For faster display through calling the HTMLColor function,
  114.     //    Set the first possible anchor in or past the read offset
  115.     //    now.
  116.     ssi_fasterpussycat = 0;
  117.     if(TNSCp_anchors->getCount())    {
  118.         auto ccIndex ccI;
  119.         auto TextAttribute *TAp_fasterpussycat;
  120.  
  121.         for(ccI = 0; ccI < TNSCp_anchors->getCount(); ccI++)    {
  122.             TAp_fasterpussycat = (TextAttribute *)(TNSCp_anchors
  123.                 ->at(ccI));
  124.             //    Break out if the end of this anchor
  125.             //    is greater than the beginning of the offset.
  126.             if(TAp_fasterpussycat->getEnd() >= sli_offset)
  127.             {
  128.                 break;
  129.             }
  130.         }
  131.  
  132.         //    If none are found, mark it as the index anyway,
  133.         //    will cause loop in HTMLColor to now execute.
  134.         ssi_fasterpussycat = ccI;
  135.     }
  136.  
  137.     //    Loop through the viewable lines in the view.
  138.     for(unsigned short int usi_screen = 0U; usi_screen < size.y;
  139.         usi_screen++)    {
  140.  
  141.         //    Fill the draw buffer with spaces.
  142.         TDB.moveChar(0, ' ', TextColor, size.x);
  143.  
  144.         //    Read the line information from the file.
  145.         //    Check to see if there are lines to display.
  146.         if(delta.y + usi_screen < limit.y)    {
  147.             //    Figure the line position in our read buffer.
  148.             auto signed short int ssi_offset = (signed short int)
  149.                 ((signed long int)(TNSCp_lines->
  150.                 at(delta.y + usi_screen)) - sli_offset);
  151.             //    Fill the line structure with information.
  152.             L_draw.ssi_length = ((Line *)(cp_draw + ssi_offset))->
  153.                 ssi_length;
  154.             L_draw.ssi_indent = ((Line *)(cp_draw + ssi_offset))->
  155.                 ssi_indent;
  156.             //    Increase our current offset.
  157.             ssi_offset += sizeof(Line);
  158.  
  159.             //    Loop through the width of the view.
  160.             for(unsigned short int usi_width = 0U;
  161.                 usi_width < size.x; usi_width++)
  162.             {
  163.                 //    Continue on if nothing.
  164.                 if(usi_width + delta.x <
  165.                     L_draw.ssi_indent)    {
  166.                     continue;
  167.                 }
  168.                 //    Check the line length,
  169.                 //    if beyond no use in continuing
  170.                 if(usi_width + delta.x >=
  171.                     L_draw.ssi_indent +
  172.                     L_draw.ssi_length)    {
  173.                     break;
  174.                 }
  175.  
  176.                 //    Continue if the character is a \r
  177.                 //    Display's funny.
  178.                 if(*(cp_draw + ssi_offset) == '\r')    {
  179.                     continue;
  180.                 }
  181.  
  182.                 //    display since in the line.
  183.                 TDB.putAttribute(usi_width, HTMLColor(
  184.                     sli_offset + (signed long int)
  185.                     ssi_offset, usi_colorindex));
  186.                 TDB.putChar(usi_width,
  187.                     *(cp_draw + ssi_offset));
  188.                 ssi_offset++;
  189.             }
  190.         }
  191.  
  192.         //    Draw the buffer to the view.
  193.         writeBuf(0, usi_screen, size.x, 1, TDB);
  194.     }
  195.  
  196.     //    Release the drawing buffer.
  197.     delete[](cp_draw);
  198. }
  199.